package fr.iut2.tc4.aideprojet2.torque.generated;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;





/**
 * Book Table
 *
 * This class was autogenerated by Torque on:
 *
 * [Mon Jan 07 12:40:11 CET 2013]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Book
 */
public abstract class BaseBook extends BaseObject
{
    /** Serial version */
    private static final long serialVersionUID = 1357558811644L;

    /** The Peer class */
    private static final BookPeer peer =
        new BookPeer();


    /** The value for the bookId field */
    private int bookId;

    /** The value for the title field */
    private String title;

    /** The value for the iSBN field */
    private String iSBN;

    /** The value for the publisherId field */
    private int publisherId;

    /** The value for the authorId field */
    private int authorId;


    /**
     * Get the BookId
     *
     * @return int
     */
    public int getBookId()
    {
        return bookId;
    }


    /**
     * Set the value of BookId
     *
     * @param v new value
     */
    public void setBookId(int v) throws TorqueException
    {

        if (this.bookId != v)
        {
            this.bookId = v;
            setModified(true);
        }



        // update associated Reference
        if (collReferences != null)
        {
            for (int i = 0; i < collReferences.size(); i++)
            {
                ((Reference) collReferences.get(i))
                        .setBookId(v);
            }
        }
    }

    /**
     * Get the Title
     *
     * @return String
     */
    public String getTitle()
    {
        return title;
    }


    /**
     * Set the value of Title
     *
     * @param v new value
     */
    public void setTitle(String v) 
    {

        if (!ObjectUtils.equals(this.title, v))
        {
            this.title = v;
            setModified(true);
        }


    }

    /**
     * Get the ISBN
     *
     * @return String
     */
    public String getISBN()
    {
        return iSBN;
    }


    /**
     * Set the value of ISBN
     *
     * @param v new value
     */
    public void setISBN(String v) 
    {

        if (!ObjectUtils.equals(this.iSBN, v))
        {
            this.iSBN = v;
            setModified(true);
        }


    }

    /**
     * Get the PublisherId
     *
     * @return int
     */
    public int getPublisherId()
    {
        return publisherId;
    }


    /**
     * Set the value of PublisherId
     *
     * @param v new value
     */
    public void setPublisherId(int v) throws TorqueException
    {

        if (this.publisherId != v)
        {
            this.publisherId = v;
            setModified(true);
        }


        if (aPublisher != null && !(aPublisher.getPublisherId() == v))
        {
            aPublisher = null;
        }

    }

    /**
     * Get the AuthorId
     *
     * @return int
     */
    public int getAuthorId()
    {
        return authorId;
    }


    /**
     * Set the value of AuthorId
     *
     * @param v new value
     */
    public void setAuthorId(int v) throws TorqueException
    {

        if (this.authorId != v)
        {
            this.authorId = v;
            setModified(true);
        }


        if (aAuthor != null && !(aAuthor.getAuthorId() == v))
        {
            aAuthor = null;
        }

    }

    



    private Publisher aPublisher;

    /**
     * Declares an association between this object and a Publisher object
     *
     * @param v Publisher
     * @throws TorqueException
     */
    public void setPublisher(Publisher v) throws TorqueException
    {
        if (v == null)
        {
            setPublisherId( 0);
        }
        else
        {
            setPublisherId(v.getPublisherId());
        }
        aPublisher = v;
    }


    /**
     * Returns the associated Publisher object.
     * If it was not retrieved before, the object is retrieved from
     * the database
     *
     * @return the associated Publisher object
     * @throws TorqueException
     */
    public Publisher getPublisher()
        throws TorqueException
    {
        if (aPublisher == null && (this.publisherId != 0))
        {
            aPublisher = PublisherPeer.retrieveByPK(SimpleKey.keyFor(this.publisherId));
        }
        return aPublisher;
    }

    /**
     * Return the associated Publisher object
     * If it was not retrieved before, the object is retrieved from
     * the database using the passed connection
     *
     * @param connection the connection used to retrieve the associated object
     *        from the database, if it was not retrieved before
     * @return the associated Publisher object
     * @throws TorqueException
     */
    public Publisher getPublisher(Connection connection)
        throws TorqueException
    {
        if (aPublisher == null && (this.publisherId != 0))
        {
            aPublisher = PublisherPeer.retrieveByPK(SimpleKey.keyFor(this.publisherId), connection);
        }
        return aPublisher;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey, for example
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setPublisherKey(ObjectKey key) throws TorqueException
    {

        setPublisherId(((NumberKey) key).intValue());
    }




    private Author aAuthor;

    /**
     * Declares an association between this object and a Author object
     *
     * @param v Author
     * @throws TorqueException
     */
    public void setAuthor(Author v) throws TorqueException
    {
        if (v == null)
        {
            setAuthorId( 0);
        }
        else
        {
            setAuthorId(v.getAuthorId());
        }
        aAuthor = v;
    }


    /**
     * Returns the associated Author object.
     * If it was not retrieved before, the object is retrieved from
     * the database
     *
     * @return the associated Author object
     * @throws TorqueException
     */
    public Author getAuthor()
        throws TorqueException
    {
        if (aAuthor == null && (this.authorId != 0))
        {
            aAuthor = AuthorPeer.retrieveByPK(SimpleKey.keyFor(this.authorId));
        }
        return aAuthor;
    }

    /**
     * Return the associated Author object
     * If it was not retrieved before, the object is retrieved from
     * the database using the passed connection
     *
     * @param connection the connection used to retrieve the associated object
     *        from the database, if it was not retrieved before
     * @return the associated Author object
     * @throws TorqueException
     */
    public Author getAuthor(Connection connection)
        throws TorqueException
    {
        if (aAuthor == null && (this.authorId != 0))
        {
            aAuthor = AuthorPeer.retrieveByPK(SimpleKey.keyFor(this.authorId), connection);
        }
        return aAuthor;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey, for example
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setAuthorKey(ObjectKey key) throws TorqueException
    {

        setAuthorId(((NumberKey) key).intValue());
    }
   


    /**
     * Collection to store aggregation of collReferences
     */
    protected List collReferences;

    /**
     * Temporary storage of collReferences to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initReferences()
    {
        if (collReferences == null)
        {
            collReferences = new ArrayList();
        }
    }


    /**
     * Method called to associate a Reference object to this object
     * through the Reference foreign key attribute
     *
     * @param l Reference
     * @throws TorqueException
     */
    public void addReference(Reference l) throws TorqueException
    {
        getReferences().add(l);
        l.setBook((Book) this);
    }

    /**
     * Method called to associate a Reference object to this object
     * through the Reference foreign key attribute using connection.
     *
     * @param l Reference
     * @throws TorqueException
     */
    public void addReference(Reference l, Connection con) throws TorqueException
    {
        getReferences(con).add(l);
        l.setBook((Book) this);
    }

    /**
     * The criteria used to select the current contents of collReferences
     */
    private Criteria lastReferencesCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getReferences(new Criteria())
     *
     * @return the collection of associated objects
     * @throws TorqueException
     */
    public List getReferences()
        throws TorqueException
    {
        if (collReferences == null)
        {
            collReferences = getReferences(new Criteria(10));
        }
        return collReferences;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Book has previously
     * been saved, it will retrieve related References from storage.
     * If this Book is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getReferences(Criteria criteria) throws TorqueException
    {
        if (collReferences == null)
        {
            if (isNew())
            {
               collReferences = new ArrayList();
            }
            else
            {
                criteria.add(ReferencePeer.BOOK_ID, getBookId() );
                collReferences = ReferencePeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.add(ReferencePeer.BOOK_ID, getBookId());
                if (!lastReferencesCriteria.equals(criteria))
                {
                    collReferences = ReferencePeer.doSelect(criteria);
                }
            }
        }
        lastReferencesCriteria = criteria;

        return collReferences;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getReferences(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getReferences(Connection con) throws TorqueException
    {
        if (collReferences == null)
        {
            collReferences = getReferences(new Criteria(10), con);
        }
        return collReferences;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Book has previously
     * been saved, it will retrieve related References from storage.
     * If this Book is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getReferences(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collReferences == null)
        {
            if (isNew())
            {
               collReferences = new ArrayList();
            }
            else
            {
                 criteria.add(ReferencePeer.BOOK_ID, getBookId());
                 collReferences = ReferencePeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                 criteria.add(ReferencePeer.BOOK_ID, getBookId());
                 if (!lastReferencesCriteria.equals(criteria))
                 {
                     collReferences = ReferencePeer.doSelect(criteria, con);
                 }
             }
         }
         lastReferencesCriteria = criteria;

         return collReferences;
     }











    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Book is new, it will return
     * an empty collection; or if this Book has previously
     * been saved, it will retrieve related References from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Book.
     */
    protected List getReferencesJoinBook(Criteria criteria)
        throws TorqueException
    {
        if (collReferences == null)
        {
            if (isNew())
            {
               collReferences = new ArrayList();
            }
            else
            {
                criteria.add(ReferencePeer.BOOK_ID, getBookId());
                collReferences = ReferencePeer.doSelectJoinBook(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(ReferencePeer.BOOK_ID, getBookId());
            if (!lastReferencesCriteria.equals(criteria))
            {
                collReferences = ReferencePeer.doSelectJoinBook(criteria);
            }
        }
        lastReferencesCriteria = criteria;

        return collReferences;
    }









    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Book is new, it will return
     * an empty collection; or if this Book has previously
     * been saved, it will retrieve related References from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Book.
     */
    protected List getReferencesJoinReader(Criteria criteria)
        throws TorqueException
    {
        if (collReferences == null)
        {
            if (isNew())
            {
               collReferences = new ArrayList();
            }
            else
            {
                criteria.add(ReferencePeer.BOOK_ID, getBookId());
                collReferences = ReferencePeer.doSelectJoinReader(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(ReferencePeer.BOOK_ID, getBookId());
            if (!lastReferencesCriteria.equals(criteria))
            {
                collReferences = ReferencePeer.doSelectJoinReader(criteria);
            }
        }
        lastReferencesCriteria = criteria;

        return collReferences;
    }



        
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
            fieldNames.add("BookId");
            fieldNames.add("Title");
            fieldNames.add("ISBN");
            fieldNames.add("PublisherId");
            fieldNames.add("AuthorId");
            fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by field (Java) name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
        if (name.equals("BookId"))
        {
            return new Integer(getBookId());
        }
        if (name.equals("Title"))
        {
            return getTitle();
        }
        if (name.equals("ISBN"))
        {
            return getISBN();
        }
        if (name.equals("PublisherId"))
        {
            return new Integer(getPublisherId());
        }
        if (name.equals("AuthorId"))
        {
            return new Integer(getAuthorId());
        }
        return null;
    }

    /**
     * Set a field in the object by field (Java) name.
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByName(String name, Object value )
        throws TorqueException, IllegalArgumentException
    {
        if (name.equals("BookId"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setBookId(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Title"))
        {
            // Object fields can be null
            if (value != null && ! String.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setTitle((String) value);
            return true;
        }
        if (name.equals("ISBN"))
        {
            // Object fields can be null
            if (value != null && ! String.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setISBN((String) value);
            return true;
        }
        if (name.equals("PublisherId"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setPublisherId(((Integer) value).intValue());
            return true;
        }
        if (name.equals("AuthorId"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setAuthorId(((Integer) value).intValue());
            return true;
        }
        return false;
    }

    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
        if (name.equals(BookPeer.BOOK_ID))
        {
            return new Integer(getBookId());
        }
        if (name.equals(BookPeer.TITLE))
        {
            return getTitle();
        }
        if (name.equals(BookPeer.ISBN))
        {
            return getISBN();
        }
        if (name.equals(BookPeer.PUBLISHER_ID))
        {
            return new Integer(getPublisherId());
        }
        if (name.equals(BookPeer.AUTHOR_ID))
        {
            return new Integer(getAuthorId());
        }
        return null;
    }

    /**
     * Set field values by Peer Field Name
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPeerName(String name, Object value)
        throws TorqueException, IllegalArgumentException
    {
      if (BookPeer.BOOK_ID.equals(name))
        {
            return setByName("BookId", value);
        }
      if (BookPeer.TITLE.equals(name))
        {
            return setByName("Title", value);
        }
      if (BookPeer.ISBN.equals(name))
        {
            return setByName("ISBN", value);
        }
      if (BookPeer.PUBLISHER_ID.equals(name))
        {
            return setByName("PublisherId", value);
        }
      if (BookPeer.AUTHOR_ID.equals(name))
        {
            return setByName("AuthorId", value);
        }
        return false;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
        if (pos == 0)
        {
            return new Integer(getBookId());
        }
        if (pos == 1)
        {
            return getTitle();
        }
        if (pos == 2)
        {
            return getISBN();
        }
        if (pos == 3)
        {
            return new Integer(getPublisherId());
        }
        if (pos == 4)
        {
            return new Integer(getAuthorId());
        }
        return null;
    }

    /**
     * Set field values by its position (zero based) in the XML schema.
     *
     * @param position The field position
     * @param value field value
     * @return True if value was set, false if not (invalid position / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPosition(int position, Object value)
        throws TorqueException, IllegalArgumentException
    {
    if (position == 0)
        {
            return setByName("BookId", value);
        }
    if (position == 1)
        {
            return setByName("Title", value);
        }
    if (position == 2)
        {
            return setByName("ISBN", value);
        }
    if (position == 3)
        {
            return setByName("PublisherId", value);
        }
    if (position == 4)
        {
            return setByName("AuthorId", value);
        }
        return false;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
        save(BookPeer.DATABASE_NAME);
    }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
     *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
        try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
    }

    /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
        if (!alreadyInSave)
        {
            alreadyInSave = true;



            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    BookPeer.doInsert((Book) this, con);
                    setNew(false);
                }
                else
                {
                    BookPeer.doUpdate((Book) this, con);
                }
            }


            if (collReferences != null)
            {
                for (int i = 0; i < collReferences.size(); i++)
                {
                    ((Reference) collReferences.get(i)).save(con);
                }
            }
            alreadyInSave = false;
        }
    }


    /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param key bookId ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
        setBookId(((NumberKey) key).intValue());
    }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
        setBookId(Integer.parseInt(key));
    }


    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
        return SimpleKey.keyFor(getBookId());
    }
 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     */
    public Book copy() throws TorqueException
    {
        return copy(true);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     *
     * @param con the database connection to read associated objects.
     */
    public Book copy(Connection con) throws TorqueException
    {
        return copy(true, con);
    }

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     */
    public Book copy(boolean deepcopy) throws TorqueException
    {
        return copyInto(new Book(), deepcopy);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     * @param con the database connection to read associated objects.
     */
    public Book copy(boolean deepcopy, Connection con) throws TorqueException
    {
        return copyInto(new Book(), deepcopy, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     */
    protected Book copyInto(Book copyObj) throws TorqueException
    {
        return copyInto(copyObj, true);
    }

  
    /**
     * Fills the copyObj with the contents of this object using connection.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param con the database connection to read associated objects.
     */
    protected Book copyInto(Book copyObj, Connection con) throws TorqueException
    {
        return copyInto(copyObj, true, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     */
    protected Book copyInto(Book copyObj, boolean deepcopy) throws TorqueException
    {
        copyObj.setBookId(bookId);
        copyObj.setTitle(title);
        copyObj.setISBN(iSBN);
        copyObj.setPublisherId(publisherId);
        copyObj.setAuthorId(authorId);

        copyObj.setBookId( 0);

        if (deepcopy)
        {


        List vReferences = getReferences();
        if (vReferences != null)
        {
            for (int i = 0; i < vReferences.size(); i++)
            {
                Reference obj = (Reference) vReferences.get(i);
                copyObj.addReference(obj.copy());
            }
        }
        else
        {
            copyObj.collReferences = null;
        }
        }
        return copyObj;
    }
        
    
    /**
     * Fills the copyObj with the contents of this object using connection.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     * @param con the database connection to read associated objects.
     */
    protected Book copyInto(Book copyObj, boolean deepcopy, Connection con) throws TorqueException
    {
        copyObj.setBookId(bookId);
        copyObj.setTitle(title);
        copyObj.setISBN(iSBN);
        copyObj.setPublisherId(publisherId);
        copyObj.setAuthorId(authorId);

        copyObj.setBookId( 0);

        if (deepcopy)
        {


        List vReferences = getReferences(con);
        if (vReferences != null)
        {
            for (int i = 0; i < vReferences.size(); i++)
            {
                Reference obj = (Reference) vReferences.get(i);
                copyObj.addReference(obj.copy(con), con);
            }
        }
        else
        {
            copyObj.collReferences = null;
        }
        }
        return copyObj;
    }
    
    

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public BookPeer getPeer()
    {
        return peer;
    }

    /**
     * Retrieves the TableMap object related to this Table data without
     * compiler warnings of using getPeer().getTableMap().
     *
     * @return The associated TableMap object.
     */
    public TableMap getTableMap() throws TorqueException
    {
        return BookPeer.getTableMap();
    }


    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Book:\n");
        str.append("BookId = ")
           .append(getBookId())
           .append("\n");
        str.append("Title = ")
           .append(getTitle())
           .append("\n");
        str.append("ISBN = ")
           .append(getISBN())
           .append("\n");
        str.append("PublisherId = ")
           .append(getPublisherId())
           .append("\n");
        str.append("AuthorId = ")
           .append(getAuthorId())
           .append("\n");
        return(str.toString());
    }
}
